package com.cjc.okhttp;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class test11 {
	public static void main(String[] args) {
		String time1="2015/08/25";
		String time2="2015/2/21";
		String formatType="yyyy/MM/dd";
		System.out.println(getMonthSpace(time1, time2, formatType));
	}

	public static int getMonthSpace(String date1, String date2, String formatType) {
		int result = 0;
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(formatType);
			Calendar c1 = Calendar.getInstance();
			Calendar c2 = Calendar.getInstance();
			c1.setTime(sdf.parse(date1));
			c2.setTime(sdf.parse(date2));
			System.out.println(c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR));
			result = c2.get(Calendar.MONDAY) - c1.get(Calendar.MONTH);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result == 0 ? 1 : Math.abs(result);
	}
}
